package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.ReferenceProxy;
	import vn.demand.dragon.view.ProjectNewFormMediator;
	import vn.demand.dragon.view.components.ProjectForm;
	
	public class NewProjectCommand extends SimpleCommand
	{
		public static var countNewProject:int = 0;
		
		override public function execute( note:INotification ) :void    
		{
			var projectVO:Object = {project_iso_code: 'New reference ' + (++countNewProject), project_rstatus: 10};
            var formId:String = ProjectNewFormMediator.makeId(projectVO);
			RIALogger.debug(this, "new project " + formId);
			if (facade.hasMediator(formId)) {
				TabManager.openTab(ProjectNewFormMediator, formId);
				return;
			}
			var ui:ProjectForm = TabManager.openTab(ProjectForm, formId) as ProjectForm;
            facade.registerMediator(new ProjectNewFormMediator(projectVO, formId, ui));
            if (!facade.hasProxy(ReferenceProxy.NAME)) {
	            facade.registerProxy(new ReferenceProxy(ReferenceProxy.NAME));
            }
        }

	}
}